package ZY11_23;
import java.io.*;
import java.net.Socket;
import java.util.*;
//用户
public class Test1LoginThread extends Thread {
    private final Socket s;
//    private static Map<String,String> map=new HashMap<>();
    List<Test1User>list =new ArrayList<>();
//    static{
//        map.put("zhangsan","123456");
//        map.put("lisi","654321");
//        map.put("wangerma","11111111");
//
//    }
    public Test1LoginThread(Socket s){
        this.s=s;
        list.add(new Test1User("zhangsan","123456"));
        list.add(new Test1User("lisi","654321"));
    }

    @Override
    public void run() {
        System.out.println("socket连接建立了" + s);
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            PrintWriter pw = new PrintWriter(out, true);
            String name=br.readLine();
            String pass=br.readLine();
            for (Test1User u:list){
                if (name.equals(u.getName())&&pass.equals(u.getPass())){
                    pw.println("登陆成功");
                }else {
                    pw.println("登录失败");
                }
            }
//            if(pass.equals(map.get(name))){
//                pw.println("登录成功");
//            }else{
//                pw.println("登录失败！");
//            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                s.close();
                System.out.println(s+"聊天结束");
            } catch (Exception e) {

            }
        }
    }
}
